<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>2 减少DOM操作</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      border: 6px solid pink;
    }
  </style>
</head>

<body>
  <div class="box"></div>
  <script>
    let len = 3;
    let frag = document.createDocumentFragment();

    for (let i = 0; i < len; i++) {
      let h4 = document.createElement("h4");
      h4.innerHTML = `CREATE H4：${i}`;
      frag.appendChild(h4);
    }

    let box = document.querySelector(".box")

    box.appendChild(frag)
  </script>
</body>

</html>